/*
 * @Author: 
 * @Date: 2021-03-29 09:55:08
 * @LastEditTime: 2021-03-29 16:57:47
 * @LastEditors: 
 * @Description: 慢查询中间件
 * @FilePath: /zhufeng_egg.js_2103/egg-example/app/middleware/slow.js
 * '
 */
'use strict';


// async function gzip(ctx, next) {
//   // 前置代码
//   await next()
//   // 后置代码
// }

module.exports = (options, app) => {
  return async (ctx, next) => {
    console.log("options, app",options, app);
    const startTime = Date.now(); // 记录开始时间
    await next();
    const consume = Date.now() - startTime; // 记录总耗时
    const { threshold = 0 } = options || {};
    if (consume > threshold) {
      // 如果耗时超过指定阈值就打印日志
      console.log(`${ctx.url}请求耗时${consume}毫秒`);
    }
  };
};
